Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup funder fee buffer #1364

Merged
merged 1 commit into from
Sep 29, 2020
Merged

Fixup funder fee buffer #1364

merged 1 commit into from
Sep 29, 2020

Conversation

t-bast
Copy link
Member

@t-bast t-bast commented Apr 2, 2020

We were previously only counting the additional HTLC at twice
the current feerate.

An HTLC in isolation doesn't make much sense: the feerate
applies to the whole commit tx. Our fee buffer needs to account
for a x2 feerate increase on the commit tx + an additional htlc.

Note that this introduces another subtlety. The commit tx fee at twice the
current feerate may actually be lower than the commit tx fee at the current
feerate (if the commit tx contains many htlcs that are only slightly above
the trim threshold).

See lightning/bolts#740 (comment) for context.

@t-bast t-bast requested a review from pm47 April 7, 2020 06:55
val funderFeeBuffer = commitTxFeeMsat(commitments1.remoteParams.dustLimit, reduced.copy(feeratePerKw = 2 * reduced.feeratePerKw)) + htlcOutputFee(2 * reduced.feeratePerKw)
// NB: increasing the feerate can actually remove htlcs from the commit tx (if they fall below the trim threshold)
// which may result in a lower commit tx fee; this is why we take the max of the two.
val missingForSender = reduced.toRemote - commitments1.remoteParams.channelReserve - (if (commitments1.localParams.isFunder) fees.max(funderFeeBuffer.truncateToSatoshi) else 0.sat)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this is not what c-lightning has implemented: https://github.com/ElementsProject/lightning/blob/af7e87930878117a0633bb7a8cd4488b8e9c5b6d/channeld/full_channel.c#L430-L440

they trim htlcs at the current feerate, and then double the feerate and not trim again

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what do you think of it? I think their choice is a bit weird and the additional reserve it ends up adding may be too big, but that's just my opinion.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were to plot the commitment tx fees as a function of feerate, because of trimming, I expect it would be a spiky curve. This PR atm (sort of) takes the max of two samplings, while c-lightning takes a conservative upper bound.
As feerates change, the max of two samplings might be lower than the actual commitment tx fees, and potentially the issue the additional reserve is trying to fix could resurface (i.e. the fee spike buffer that is supposed to handle fee spikes up to 2x of current feerate might not be sufficient to handle all feerates in between). Though admittedly I did not look at specific numbers so perhaps this is highly unlikely in practice.

My personal opinion is that it might make more sense to take an upper bound of the curve, as c-lightning does, as then that should cover all possible feerates up to the chosen parameter (of "2x").

Copy link
Member Author

@t-bast t-bast Apr 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were to plot the commitment tx fees as a function of feerate, because of trimming, I expect it would be a spiky curve.

Yes exactly, and that can be surprising at first!

the issue the additional reserve is trying to fix could resurface (i.e. the fee spike buffer that is supposed to handle fee spikes up to 2x of current feerate might not be sufficient to handle all feerates in between).

Yes but only temporarily, because the HTLCs you have in the commit tx will eventually settle.
Once they settle that gives you money back and unblocks the channel. And I think that's an important insight.

Taking the conservative upper bound also works, but it means there's more of your channel balance that you just can't use, which I want to avoid unless absolutely necessary. It's already hard to tell users "you put X mBTC in this channel but in fact what you'll be able to use is less than that, but trust us, this is necessary", so let's not add more to that if we can avoid it. Does that make sense?

@t-bast t-bast force-pushed the stuck-channels-fixup branch from f981f63 to fbe4529 Compare July 2, 2020 09:22
@t-bast
Copy link
Member Author

t-bast commented Sep 8, 2020

What should we do about this PR @pm47?

We haven't noticed the stuck channel issue at all for months, which means the previous fix is enough to mitigate it.
Merging this PR would make us "more" spec-compliant but wastes a bit more liquidity than what we currently have, so I'm not sure we should merge unless users heavily request that.

We were previously only counting the additional HTLC at twice
the current feerate.

An HTLC in isolation doesn't make much sense: the feerate
applies to the whole commit tx. Our fee buffer needs to account
for a x2 feerate increase on the commit tx + an additional htlc.

Note that this introduces another subtlety. The commit tx fee at twice the
current feerate may actually be lower than the commit tx fee at the current
feerate (if the commit tx contains many htlcs that are only slightly above
the trim threshold).
@t-bast t-bast force-pushed the stuck-channels-fixup branch from fbe4529 to 97c9b57 Compare September 28, 2020 13:40
@t-bast t-bast merged commit 8a27b4c into master Sep 29, 2020
@t-bast t-bast deleted the stuck-channels-fixup branch September 29, 2020 16:06
t-bast added a commit to ACINQ/lightning-kmp that referenced this pull request Oct 9, 2020
See ACINQ/eclair#1364 for details.

We are now spec-compliant.
t-bast added a commit to ACINQ/lightning-kmp that referenced this pull request Oct 12, 2020
* Remove unused check in Commitments.sendAdd
* Clean-up commitments
* Update funder fee buffer (ACINQ/eclair#1364)
// - commit tx fee at twice the feerate = 724 * 2000 = 1448 sat (all HTLCs have been trimmed)
// - cost of an additional untrimmed HTLC = 172 * 2000 = 344 sat
// - funder fee buffer = 1448 + 344 = 1792 sat
// In that case the current commit tx fee is higher than the funder fee buffer and will dominate the balance restrictions.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a fee-buffer can act in two different directions, meaning that in case of a down-spike former dust htlcs can use this buffer as well. So I would argue to not really dynamically simulate a 2x increase in the feerate and based of this calculate the feebuffer but rather just take the worst case scenario and account for the double fee at the current feerate (thats basically a 2x simulation without taking any trimmed htlcs into account) ? Why not consider tripped htlcs? Because trimmed htlcs are accounted for fees anyways. So in your above example when all 10 htlcs are trimmed, we have a final fee of
0.724 * 2000 + 10 * 1250 = 13950 sasts, so we could just keep the double fee as a buffer because this would have the advantage, if there are already trimmed away htlcs on the commitment, the feerate could also be decreased in an event of a fee-dump ? wdyt ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants